<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Display numbers like ordernumber e.g.
 * use numbers.tpl.php
 * 
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
function contentPage($refPage, $page, $subpage, $refValidate)
{
	if (isset($_REQUEST['submit']))
	{
		if ($refValidate->cleanslash($_REQUEST['submit']) === _('Save'))
		{
			// Update the database
			$datax = $refValidate->cleanslash($_POST['ordernumberx']) . '.00';

			if (!empty($datax))
			{
				$data = Array('config_value' => $datax);
				db::getInstance()->where('config_key', 'ordernumber');
				db::getInstance()->update('config', $data);

				$datax = $refValidate->cleanslash($_POST['customernumberx']);

				$data = Array('config_value' => $datax);
				db::getInstance()->where('config_key', 'customernumber');

				if (db::getInstance()->update('config', $data))
					message::setNoteRow(_('The data was successful saved.'), true);
			}
		}
	}

	db::getInstance()->where('config_key', 'ordernumber');
	$orderx = db::getInstance()->getOne('config');
	db::getInstance()->where('config_key', 'customernumber');
	$customerx = db::getInstance()->getOne('config');

	$refPage->assign('action', 'index2.php?page=' . $page . '&sub=' . $subpage);

	$refPage->assign('ordernumber', _('Order-number'));
	$refPage->assign('ordernumberx', intval($orderx['config_value']));
	$refPage->assign('ordernumberxHelp', help('ordernumber', $page));

	$refPage->assign('customernumber', _('Customernumber'));
	$refPage->assign('customernumberx', intval($customerx['config_value']));
	$refPage->assign('customernumberxHelp', help('customernumber', $page));


	$refPage->assign('save',
		'<input type="submit" name="submit" id="save" value="' .
		_('Save') . '" />');

	$refPage->assign('abort', '<input type="reset" value="' . _('Abort') . '">');

	$refPage->assign('name', _('Numbers'));
	$refPage->assign('scripts',
		'<script type="text/javascript" src="' .
		'module/ckeditor/ckeditor.js"></script>');
	$refPage->addtpl('content', '/config/numbers.tpl.php');
}

?>